﻿using System.Collections.ObjectModel;
using System.Windows;
using Microsoft.Win32;

namespace DependencyVisualizer
{
    public partial class SelectAssembliesPage
    {
        private readonly ObservableCollection<string> _fileNames = new ObservableCollection<string>();

        public ObservableCollection<string> FileNames
        {
            get { return _fileNames; }
        }

        public SelectAssembliesPage()
        {
            InitializeComponent();
            files.ItemsSource = _fileNames;
        }

        private void AddAssemblyClick(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog { Filter = "Assembly|*.dll;*.exe;*.winmd", Multiselect = true };
            openFileDialog.ShowDialog();
            var filesNames = openFileDialog.FileNames;
            if (filesNames != null)
            {
                foreach (var file in filesNames)
                {
                    _fileNames.Add(file);
                }
            }
        }

        private void ResetClick(object sender, RoutedEventArgs e)
        {
            _fileNames.Clear();
        }

        private void Confirm(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void Remove(object sender, RoutedEventArgs e)
        {
            var element = sender as FrameworkElement;
            if (element == null)
            {
                return;
            }
            var assemblyToRemove = "" + element.DataContext;
            _fileNames.Remove(assemblyToRemove);
        }
    }
}
